package com.cn.happymall.common;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * @ClassName ServerResponse
 * @Description TODO(这里用一句话描述这个类的作用)  响应结果数据模型
 * @author hasee
 * @Date 2017年12月25日 下午2:10:21
 * @version 1.0.0
 */
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class ServerResponse {

	private int status;
	private String msg;
	private Object data;

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	private ServerResponse(int status, String msg) {
		this.status = status;
		this.msg = msg;
	}

	private ServerResponse(int status, Object data) {
		this.status = status;
		this.data = data;
	}

	private ServerResponse(int status, String msg, Object data) {
		this.status = status;
		this.msg = msg;
		this.data = data;
	}

	/*@JsonIgnore
	public boolean isSuccess() {
		return status == ResponseCode.SUCCESS ? true : false;
	}*/

	public static ServerResponse createSuccess(String msg) {
		return new ServerResponse(ResponseCode.SUCCESS, msg);
	}

	public static ServerResponse createSuccess(Object data) {
		return new ServerResponse(ResponseCode.SUCCESS, data);
	}

	public static ServerResponse createFailure(String msg) {
		return new ServerResponse(ResponseCode.ERROR, msg);
	}

}
